package com.yunhe.rentcars.pro.controller.system;

import com.yunhe.rentcars.commons.dto.JSONResponse;
import com.yunhe.rentcars.commons.dto.Pageable;
import com.yunhe.rentcars.pro.entity.system.ClientLevel;
import com.yunhe.rentcars.pro.service.system.ClientLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/clientlevel")
public class ClientLevelController {
    @Autowired
    private ClientLevelService clientLevelService;
//跳转到列表页
    @RequestMapping
    public String clientlevellist(){
        return "system/clientlevel/clientlevellist";
    }
    //跳转到添加页面
    @RequestMapping("/add")
    public String add(){
        return "system/clientlevel/clientleveladd";
    }
//获取分页查找的数据
    @RequestMapping("/listData")
    @ResponseBody
    public Pageable<ClientLevel> listData(Integer offset, Integer limit){
        return clientLevelService.findPage(offset,limit);
    }

    //跳转到编辑页面
    @RequestMapping("/edit")
    public String edit(Long id, HttpServletRequest request){
        ClientLevel clientLevel = clientLevelService.findOne(id);
        request.setAttribute("clientlevel",clientLevel);
        return "system/clientlevel/clientleveledit";
    }

    //  添加方法
    @RequestMapping("/save")
    @ResponseBody
    public JSONResponse save(ClientLevel clientLevel){
        if(null != clientLevel){
            clientLevelService.save(clientLevel);
        }
        return JSONResponse.success("添加成功");
    }

    //删除方法
    @RequestMapping("/delete")
    @ResponseBody
    public JSONResponse delete(String ids){

        if(null != ids){
            String[] split = ids.split(",");
            for(String id : split) {
                clientLevelService.delete(Long.valueOf(id));
            }
        }
        return JSONResponse.success("删除成功！");
    }
    @RequestMapping("update")
    @ResponseBody
    public JSONResponse update(ClientLevel clientLevel){
        clientLevelService.update(clientLevel);
        return JSONResponse.success("修改成功！");
    }

}
